<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="common/include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-role-add" th:object="${user}">
        <input id="id" name="id" type="hidden" th:field="*{id}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">(默认自动获取)uuid：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="userId" id="userId" th:field="*{userId}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">用户名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="username" id="username" required="required" th:field="*{username}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">邮箱：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="email" id="email" th:field="*{email}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">电话：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="phone" id="phone" th:field="*{phone}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">性别：</label>
            <div class="col-sm-8">
                <select id="sex" class="form-control" required="required">
                    <option value="0">请选择</option>
                    <option value="1">男</option>
                    <option value="2">女</option>
                    <option value="3">未知</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">年龄：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="age" id="age" th:field="*{age}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">用户状态：</label>
            <div class="col-sm-8">
                <div class="onoffswitch">
                    <input type="checkbox" th:checked="${user.status == '1' ? true : false}" class="onoffswitch-checkbox" id="status" name="status">
                    <label class="onoffswitch-label" for="status">
                        <span class="onoffswitch-inner"></span>
                        <span class="onoffswitch-switch"></span>
                    </label>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }
    function add() {
        var id = $("input[name='id']").val();
        var username = $("input[name='username']").val();
        var email = $("input[name='email']").val();
        var phone = $("input[name='phone']").val();
        var sex = $("#sex option:selected").val();
        var age = $("input[name='age']").val();
        var status = $("input[name='status']").is(':checked') == true ? 1 : 2;
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "user/edit",
            data : {
                "id": id,
                "username": username,
                "email":email,
                "phone":phone,
                "sex":sex,
                "age":age,
                "status":status
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(json) {
                if(json.status == 200){
                    $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
                }else {
                    $.modal.alertError(json.message);
                }
            }
        });
    }
</script>
</body>
</html>